<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2021/4/13
  Time: 13:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>新增员工</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/xadmin.js"></script>

</head>

<body onload="choiceJob()">
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="bh" class="layui-form-label">
                <span class="x-red">*</span>编号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="bh" name="username" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" placeholder="7位数字">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="zh" class="layui-form-label">
                <span class="x-red">*</span>账号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="zh"
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="mm" class="layui-form-label">
                <span class="x-red">*</span>密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="mm" name="email"
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="xm" class="layui-form-label">
                <span class="x-red">*</span>姓名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="xm"
                       class="layui-input" placeholder="">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="bm" class="layui-form-label">
                <span class="x-red">*</span>部门
            </label>
            <div class="layui-input-inline">
                <input type="text" id="bm"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="zw" class="layui-form-label">
                <span class="x-red">*</span>职位
            </label>
            <div class="layui-input-inline">
                <%--                <input type="password" id="L_repass" name="repass" required="" lay-verify="repass"--%>
                <%--                       autocomplete="off" class="layui-input">--%>
                <select id="zw" class="layui-input">

                    <%--显示职位--%>
                </select>

            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">选择职位</span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="nl" class="layui-form-label">
                <span class="x-red">*</span>年龄
            </label>
            <div class="layui-input-inline">
                <input type="text" id="nl"
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="xb" class="layui-form-label">
                <span class="x-red">*</span>性别
            </label>
            <div class="layui-input-inline">
                <input type="text" id="xb"
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="yx" class="layui-form-label">
                <span class="x-red">*</span>邮箱
            </label>
            <div class="layui-input-inline">
                <input type="email" id="yx"
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="dh" class="layui-form-label">
                <span class="x-red">*</span>电话
            </label>
            <div class="layui-input-inline">
                <input type="text" id="dh"
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" type="button" onclick="add()">
                增加
            </button>
        </div>
    </form>
</div>
<script>
    function add() {
        var bh = $("#bh").val();
        var zh = $("#zh").val();
        var mm = $("#mm").val();
        var xm = $("#xm").val();
        var bm = $("#bm").val();
        var zw = $("#zw").val();
        var nl = $("#nl").val();
        var xb = $("#xb").val();
        var yx = $("#yx").val();
        var dh = $("#dh").val();
        $.ajax({
            url: "${pageContext.request.contextPath}/employee/addEmployee",
            type: "get",
            data: {
                "eNumber": bh,
                "eName": zh,
                "ePwd": mm,
                "name": xm,
                "depa": bm,
                "job": zw,
                "age": nl,
                "sex": xb,
                "eMail": yx,
                "phone": dh
            },
            dataType: "json",
            success: function (data) {
                alert(data.info);
                window.location.href = "${pageContext.request.contextPath}/employee/turnEmployeePage";
            }
        });
    }
</script>
<script>
    function choiceJob() {
        $.ajax({
            url: "${pageContext.request.contextPath}/job/allJob",
            dataType: "json",
            success: function (data) {
                console.log(data);
                if (typeof (data.info) == "string") {
                    $("#zw").html("");
                } else {
                    var zw = $("#zw");
                    $.each(data.info, function (index, item) {
                        console.log(item.jNameCh);
                        zw.append("<option>" + item.jNameCh + "</option>")
                    });
                    renderForm();

                   // var html = "";
                    /*for (var i = 0; i < data.info.length; i++) {
                        // html += "<option>" + data.info[i].jNameCh + "</option>"
                        // console.log("<option>" + data.info[i].jNameCh + "</option>");
                    }*/
                    // $("#zw").html(html);

                }
            }
        })
    }
    //重新渲染表单
    function renderForm() {
        layui.use('form', function () {
            var form = layui.form;
            form.render();
        });
    }
</script>
</body>
</html>
